﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class ChiTietHoaDonDAO
    {
        public List<shop_chitiethoadon> LayDanhSachChiTietHoaDon()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var cthd = from c in EFashionDB.shop_chitiethoadons select c;
            return cthd.ToList();
        }

        public shop_chitiethoadon LayChiTietHoaDonsTheoMa(int MaChiTietHoaDon)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_chitiethoadon cthd = EFashionDB.shop_chitiethoadons.Single(c => c.MaChiTietHoaDon == MaChiTietHoaDon);
            return cthd;
        }

        public void XoaChiTietHoaDon(int MaChiTietHoaDon)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var cthd = (from c in EFashionDB.shop_chitiethoadons
                      where c.MaChiTietHoaDon == MaChiTietHoaDon
                      select c);
            EFashionDB.shop_chitiethoadons.DeleteAllOnSubmit(cthd);
            EFashionDB.SubmitChanges();
        }

        public void CapNhatChiTietHoaDon(shop_chitiethoadon cthdLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_chitiethoadon cthd = EFashionDB.shop_chitiethoadons.Single(c => c.MaChiTietHoaDon == cthdLinq.MaChiTietHoaDon);
            cthd.MaHoaDon = cthdLinq.MaHoaDon;
            cthd.MaSanPham = cthdLinq.MaSanPham;
            cthd.SoLuong = cthdLinq.SoLuong;
            cthd.TenSanPham = cthdLinq.TenSanPham;
            cthd.DonGia = cthdLinq.DonGia;

            EFashionDB.SubmitChanges();
        }

        public void ThemChiTietHoaDon(shop_chitiethoadon cthdLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_chitiethoadons.InsertOnSubmit(cthdLinq);

            EFashionDB.SubmitChanges();
        }

        /************************************************************************************************************        *
         * coder: TRAN KINH LY 
         ***********************************************************************************************************/
        public List<shop_chitiethoadon> LayDanhSachTheoMaHoaDon(int id_hoadon)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from cmt in EFashionDB.shop_chitiethoadons
                       where cmt.MaHoaDon == id_hoadon
                       select cmt;

            return list.ToList();
        }

        /************************************************************************************************************        *
         * coder: TRAN KINH LY 
         ***********************************************************************************************************/

    }
}
